package luanvan.bus;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import cse.luanvan.R;

public class BaseGlandBusAdapter extends BaseAdapter {

	private static String[] glandbus;
	private static Context context;
	LayoutInflater layoutInflater;

	public BaseGlandBusAdapter(Context mcontext, String[] list) {
		super();
		context = mcontext;
		this.layoutInflater = LayoutInflater.from(mcontext);
		glandbus = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return glandbus.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return glandbus[position];
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewholder;
		if (convertView == null) {
			convertView = layoutInflater.inflate(R.layout.instruction, null);
			viewholder = new ViewHolder();
			viewholder.image = (ImageView) convertView.findViewById(R.id.image);
			viewholder.txtView = (TextView) convertView
					.findViewById(R.id.content);
			convertView.setTag(viewholder);
		} else
			viewholder = (ViewHolder) convertView.getTag();

		String[] bus = glandbus[position].split(":");
		String img="n"+bus[0].trim();
		int imageID= context.getResources().getIdentifier(img, "drawable", context.getPackageName());

		viewholder.image.setImageResource(imageID);

		viewholder.txtView.setText(bus[1].trim());
		return convertView;
	}

	static class ViewHolder {
		ImageView image;
		TextView txtView;

	}

}
